<?php
/**
 * Created by PhpStorm.
 * WxUser: yf
 * Date: 2018/5/28
 * Time: 下午6:33
 */

namespace EasySwoole\EasySwoole;


use App\Process\HotReload;
use App\Redis\SubscribeEvent;
use App\X\EHelper;
use App\X\Smarty;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;
use EasySwoole\Template\Render;


class EasySwooleEvent implements Event
{

    public static function initialize()
    {
        // TODO: Implement initialize() method.
        date_default_timezone_set('Asia/Shanghai');
    }

    public static function mainServerCreate(EventRegister $register)
    {
        if (EHelper::funcIsDev())
        {
            $swoole_server = ServerManager::getInstance()->getSwooleServer();
            $swoole_server
                ->addProcess((new HotReload('HotReload', ['disableInotify' => true,]))->getProcess());
        }


        $register->add(EventRegister::onWorkerStart, function (\swoole_server $server, $workerId)
        {
            if ($workerId === 0)
            {
                SubscribeEvent::funcIns()->funcEventExpired();

//                \App\Task\queue_out::funcIns()->funcRun();
//                \App\Task\test::funcIns()->funcRun();
//
//                \App\Task\test2::funcIns()->funcRun();
            }
        });
    }

    public static function onRequest(Request $request, Response $response): bool
    {
        // TODO: Implement onRequest() method.
        return true;
    }

    public static function afterRequest(Request $request, Response $response): void
    {
        // TODO: Implement afterAction() method.
    }

    public static function onReceive(\swoole_server $server, int $fd, int $reactor_id, string $data): void
    {
        var_dump('onReceive');
    }

}